
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<title>弘云体育算分系统</title>
<meta name="keywords" content="弘云体育算分系统" />
<meta name="description" content="弘云体育算分系统" />
<link rel="stylesheet" type="text/css" href="./css/gufen/main.css" />
<link rel="stylesheet" type="text/css" href="./css/gufen/style.css" />
<link rel="stylesheet" type="text/css" href="./css/gufen/reset.css" />
<link rel="stylesheet" type="text/css" href="./css/gufen/swiper.css" />
<script type="text/javascript" src="./js/gufen/jquery.js"></script>
<script type="text/javascript" src="./js/gufen/nav.js"></script>
<script type="text/javascript" src="./js/gufen/cart_icon.js"></script>
<script type="text/javascript" src="./js/gufen/swiper.js"></script>
<script type="text/javascript" src="./js/gufen/lihe.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<div class="main">
  <div style="width:5%; float:left; padding-top:15px; margin-left:1.5%; position:fixed; z-index:99999;">
    <a href="javascript:history.back();">
      <img src="./images/fh.png" width="140%" alt="" border="0" />
    </a> 
  </div>
  <div class="header">
    <div class="head bt"> 弘云体育算分系统 </div>
  </div>
  <div class="content content_new">
    <div class="biaodan" id="chengji">
      <h3>体育四项成绩：</h3>
      <ul>
      <div class="table-c">
      <table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td bgcolor="#eeeeee">项目</td>
    <td bgcolor="#eeeeee">成绩</td>
    <td bgcolor="#eeeeee">分数</td>
  </tr>
  <tr>
    <td>100米</td>
    <td id="baimi"> </td>
    <td><strong id="m100cj">0</strong>分</td>
  </tr>
  <tr>
    <td>800米</td>
    <td id="babai"></td>
    <td><strong id="m800cj">0</strong>分</td>
  </tr>
  <tr>
    <td>立定三级跳</td>
    <td id="tiaoyuan"></td>
    <td><strong id="m3cj">0</strong>分</td>
  </tr>
  
  <tr>
    <td>铅球</td>
    <td id="qianqiu"></td>
    <td><strong id="qcj">0</strong>分</td>
  </tr>
  <tr>
    <td height="59" colspan="3" align="center">总分：<strong id="zcj">0</strong>分</td>
    </tr>
</table>
</div>
      </ul>
      <div style="height:20px; clear:both;"></div>
      <div class=" clear"></div>
    </div>
    <div class=" clear"></div>
    <div style="height:20px; clear:both;"></div>
    <div class="icontact huise">
      <p class="ab"> <img src="./images/20230308163740.jpg"><br>
        长按识别二维码，关注我们公众号<br />
        体育高考信息全知道<br />
        版权所有 &copy; 弘云体育</p>
    </div>
  </div>
</div>
<script type="text/javascript" src="./json/m3.js"></script>
<script type="text/javascript" src="./json/m100.js"></script>
<script type="text/javascript" src="./json/mq.js"></script>
<script type="text/javascript" src="./json/wo3.js"></script>
<script type="text/javascript" src="./json/wo100.js"></script>
<script type="text/javascript" src="./json/woq.js"></script>
<script type="text/javascript" src="./json/m800.js"></script>
<script type="text/javascript" src="./json/wo800.js"></script>

<script >
 
    var baimi = getUrlParam('baimi') ? getUrlParam('baimi') :0; //百米 
    var babaim = getUrlParam('babaim')? getUrlParam('babaim') :0; //八百分
    var babais = getUrlParam('babais')? getUrlParam('babais') :0; //秒 
    var babaii = getUrlParam('babai') ? getUrlParam('babai') : 0; //毫
    var tiaoyuan = getUrlParam('tiaoyuan')? getUrlParam('tiaoyuan') :0; //跳远
    var qianqiu = getUrlParam('qianqiu')? getUrlParam('qianqiu') :0; //铅球
    var sex = getUrlParam('sex'); //铅球
    var babai = babaim+padding4(babais,2)+padding4(babaii,2);
    $('#baimi').html(baimi+'秒');
    $('#babai').html(babaim+':'+padding4(babais,2)+':'+padding4(babaii,2));
    $('#tiaoyuan').html(tiaoyuan+'米');
    $('#qianqiu').html(qianqiu+'米');
    var m3cj = 0;
    var m100cj = 0;
    var m800cj = 0;
    var qcj = 0;
    //判断性别 
    if(sex == '1'){
       m3cj = countCjAsc(m3,tiaoyuan); //三级跳
       m100cj = countCjDesc(m100,baimi); //百米
       m800cj = countCjDesc(m800,babai); //八百
       qcj = countCjAsc(mq,qianqiu); //铅球
    }else if(sex == '2'){
       m3cj = countCjAsc(wo3,tiaoyuan); //三级跳
       m100cj = countCjDesc(wo100,baimi); //百米
       m800cj = countCjDesc(wo800,babai); //八百
       qcj = countCjAsc(woq,qianqiu); //铅球
    }
    var zcj = parseFloat(m3cj) +parseFloat(m100cj) + parseFloat(m800cj)+ parseFloat(qcj);    
    $('#m3cj').html(m3cj);
    $('#m100cj').html(m100cj);
    $('#m800cj').html(m800cj);
    $('#qcj').html(qcj);
    $('#zcj').html(floatToFixed(zcj,2));
    // var newArr = [];
    // for(let key in m100){
    //   newArr.unshift(m100[key]);
    // }
    // console.log(JSON.stringify(newArr));      
    // var cj = countCj(m3,tiaoyuan); 
    // console.log(cj);

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }

    function padding4(num, length) {
        //这里用slice和substr均可
        return (Array(length).join("0") + num).slice(-length);
    }

    /**
     * 计算成绩 值越大 分越高  
     * @cj_json 成绩表
     * @cj_data 成绩值
     * */
    function countCjAsc(cj_json,cj_data){
        if(!cj_data || cj_data == 0) return 0;
        cj_data = parseFloat(cj_data);
        for(let key in cj_json){
            key = parseInt(key)
            let item = cj_json[key];
            //成绩超过最大值 
            if(key == 0 && cj_data >= item.key){
                return parseFloat(item.value);
            }
            let before_item = cj_json[key-1];
            if( item.key && cj_data >= item.key && cj_data < before_item.key){
                //成绩 = 对应值 
                if(cj_data == parseFloat(item.key)){
                   return parseFloat(item.value);
                }else{  // 成绩 >= item.key 
                    //取差集 并计算差集数 
                    let diff_key  = before_item.key - item.key;
                    let diff_value  = before_item.value - item.value;
                    // console.log(before_item.key);
                    // console.log(item.key);
                    diff_key = GetRoundDd(diff_key,2)
                    let diff_count =  handleDiffCount(diff_key);
                    let key_value = diff_value/diff_count;
                    let cj_count = handleDiffCount(cj_data-item.key);
                    item.value = item.value + (cj_count*key_value);
                    // console.log(item.value)
                    //计算当前baimi多出的数
                   return Math.floor(item.value * 100) / 100; 
                }
            }
        }
        return 0;
    }

    /**
     * 计算成绩 值越小 分越高  
     * @cj_json 成绩表
     * @cj_data 成绩值
     * */
     function countCjDesc(cj_json,cj_data){
      if(!cj_data || cj_data == 0) return 0;
        cj_data = parseFloat(cj_data);
        for(let key in cj_json){
            key = parseInt(key)
            let item = cj_json[key];
            //成绩超过最大值 
            if(key == 0 && cj_data < item.key){
              return parseFloat(item.value);
            }
            let before_item = cj_json[key+1];
            if(!before_item) return 0;
            if( item.key && cj_data >= item.key && cj_data < before_item.key){
                //成绩 = 对应值 
                if(cj_data == parseFloat(item.key)){
                  return parseFloat(item.value);
                }else{  // 成绩 >= item.key 
                    //取差集 并计算差集数 
                    let diff_key  = before_item.key - item.key;
                    diff_key = GetRoundDd(diff_key,2);
                    let diff_value  = before_item.value - item.value;
                    let diff_count =  handleDiffCount(diff_key);
                    let key_value = diff_value/diff_count;
                    let cj_count = handleDiffCount(cj_data-item.key);
                    item.value = item.value + (cj_count*key_value);
                    //计算当前baimi多出的数 
                   return Math.floor(item.value * 100) / 100;
                }
            }
        }
        return 0;
    }


    /**
     * 保留3位小数 
     */
     function floatToFixed(params,fixed=3) {
 
          let newpar = parseFloat(params);

          let reg = /^[0-9]+.?[0-9]*$/;

          if(reg.test(newpar)){

              let newNum = newpar.toFixed(fixed);

              return newNum;

          }else{

              alert('请输入数字');

              return;

          }
    }



    function handleDiffCount(diff){
        return  parseFloat(diff)/0.01;
    }

     /**
   * 四舍五入 保留三位 
  */
  function GetRoundDd(num, len) {
    return num.toFixed(len);
  }




</script>

</body>
</html>
